import { http } from "@/utils/http";

interface BannerResponse {
  code: number;
  message: string;
  data?: any;
  rows?: any[];
  total?: number;
}

/** Banner 数据类型 */
export interface BannerItem {
  id?: number;
  title: string; // 内部标题
  image_url: string; // 展示图片
  placement_key: string; // 展示位置
  link_type: string; // 跳转类型: none, webpage, miniapp
  link_target: string; // 跳转目标
  sort_order: number; // 排序权重
  status: boolean; // 状态: true, false
  created_at?: string;
  updated_at?: string;
}

/** 获取 Banner 列表 */
export const getBannerList = (params?: object) => {
  return http.request<BannerResponse>("get", "/api/banners", {
    params
  });
};

/** 创建 Banner */
export const createBanner = (data: BannerItem) => {
  return http.request<BannerResponse>("post", "/api/banners", {
    data
  });
};

/** 获取 Banner 详情 */
export const getBannerDetail = (id: number) => {
  return http.request<BannerResponse>("get", `/api/banners/${id}`);
};

/** 更新 Banner */
export const updateBanner = (id: number, data: BannerItem) => {
  return http.request<BannerResponse>("put", `/api/banners/${id}`, {
    data
  });
};

/** 删除 Banner */
export const deleteBanner = (id: number) => {
  return http.request<BannerResponse>("delete", `/api/banners/${id}`);
};
